package GUI;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;

import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import papers.Manuscript;
/** @author Shawn Paul Smith - ssmith35
 *  @author Taylor Zielske
 * Provides a base class for panels that show info about
 * manuscripts.
 */
public abstract class AbstractPaperViewPanel extends JPanel {
	
	private static final long serialVersionUID =
			1905317236875847484L;
	public AbstractPaperViewPanel() {
		super();
		setLayout(new GridLayout(0, 4));
	}
	
	/** Displays the given papers in this panel. **/
	public void addPaper(final Manuscript paper) {
		JPanel pan = new JPanel();
		pan.setLayout(new BoxLayout(pan, BoxLayout.Y_AXIS));
		ImageIcon icon = new ImageIcon("images" +
				File.separator + "Manuscript.png");
		JLabel image = new JLabel(icon, JLabel.CENTER);
		image.setAlignmentX(Component.CENTER_ALIGNMENT);

		JLabel linebreak = new JLabel(" ");
		linebreak.setAlignmentX(Component.CENTER_ALIGNMENT);
		pan.add(createPaperInfoPanel(paper));
		pan.add(image);
		add(pan);
		this.repaint();
		image.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				if (JOptionPane.showConfirmDialog(
						AbstractPaperViewPanel.this,
						"Are you sure you want to delete " +
							"this paper from the conference?",
						"Delete",JOptionPane.YES_NO_OPTION)
						== JOptionPane.YES_OPTION) {
					deletePaper(paper);
				}
			}
		});
	}
	
	public JScrollPane getScrollPane(Dimension size) {
		JScrollPane pane = new JScrollPane(this);
		pane.setPreferredSize(size);
		return pane;
	}
	
	/**  Creates a JPanel that displays info or buttons
	 *  for a given paper. */
	protected abstract JPanel createPaperInfoPanel(
			Manuscript manu);
	
	/** Deletes a Manuscript from the application. */
	protected abstract void deletePaper(Manuscript manu);
	
	/** Updates the display to reflect changes in the
	 * papers to be shown. */
	public abstract void refreshPapers();
}
